package com.emr.web.controller.emr;


import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emr.common.annotation.Log;
import com.emr.common.enums.BusinessType;
import com.emr.common.support.Convert;
import com.emr.module.domain.Jianyanjg;
import com.emr.module.service.IBinglijieyueService;
import com.emr.module.service.IJianyanjgService;
import com.emr.module.service.IJieyueService;
import com.emr.system.domain.SysUser;
import com.emr.web.core.base.BaseController;
import com.emr.framework.web.page.TableDataInfo;
import com.emr.common.base.AjaxResult;

/**
 * 病历借阅 信息操作处理
 * 
 * @author emr
 * @date 2019-02-25
 */
@Controller
@RequestMapping("/module/binglijieyue")
public class BinglijieyueController extends BaseController
{
    private String prefix = "module/binglijieyue";
	
	@Autowired
	private IBinglijieyueService binglijieyueService;
	@Autowired
	private IJieyueService jieyueService;
	
	@RequiresPermissions("module:binglijieyue:view")
	@GetMapping()
	public String jianyanjg()
	{
	    return prefix + "/binglijieyue";
	}
	
	/**
	 * 病历借阅列表
	 */
	@RequiresPermissions("module:binglijieyue:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list()
	{
		//获取用户名
		SysUser user = getUser();
		List<Map<String, Object>> selectjieyuerenId = jieyueService.selectjieyuerenId(user.getUserId().intValue());
		String ids = null;
		String[] id = null;
		if(!selectjieyuerenId.isEmpty()){
			StringBuffer str = new StringBuffer();
			for(Map<String,Object> m:selectjieyuerenId){
				str.append(m.get("bingrenId")+",");
			}
			ids = str.substring(0, str.length() -1);
			id = Convert.toStrArray(ids);
		}else{
			id = Convert.toStrArray("null");
		}
		startPage();
        List<Map<String,Object>> list = binglijieyueService.selectBingLijrList(id);
		return getDataTable(list);
	}
	

}
